<?php

namespace phptools;

/**
 * Classe da interface formulario frmObfuscator
 *
 * @name IfrmObfuscator
 */
abstract class IfrmObfuscator {
	/**
	 * Armazena os widgets necessarios
	 * 
	 * @access private
	 * @name $widgets
	 * @var array
	 */
	public $widgets = array();
	
	/**
	 * @name __construct()
	 */
	public function __construct() {
		// Cria a janela
		$this->widgets['frmObfuscator'] = \Fabula::GtkWindow();
		$this->widgets['frmObfuscator']->set_size_request(600, 350);
		$this->widgets['frmObfuscator']->set_position(\GTK::WIN_POS_CENTER);
		$this->widgets['frmObfuscator']->set_title("Obfuscator");
		$box = \Fabula::GtkVBox();
		
		// Cria o toolbar
		$this->widgets['tlbMain'] = \Fabula::GtkToolbar();
		$this->widgets['tlbMain']->append_button_from_image(PHPTOOLS_PATH . "/images/open_folder.png", NULL, "Abrir");
		$this->widgets['tlbMain']->append_separator();
		$this->widgets['tlbMain']->append_button_from_image(PHPTOOLS_PATH . "/images/select_none.png", NULL, "Remover Seleção");
		$this->widgets['tlbMain']->append_button_from_image(PHPTOOLS_PATH . "/images/select_all.png", NULL, "Selecionar Todos");
		$this->widgets['tlbMain']->append_separator();
		$this->widgets['tlbMain']->append_button_from_image(PHPTOOLS_PATH . "/images/compile.png", NULL, "Obfuscar");
		$box->pack_start($this->widgets['tlbMain'], FALSE);
		
		// Cria o treeview
		$model = new \GtkListStore(\GObject::TYPE_BOOLEAN, \GObject::TYPE_STRING, \GObject::TYPE_STRING);
		$this->widgets['trvFiles'] = \Fabula::GtkTreeView($model);
		
		$cell_renderer = new \GtkCellRendererToggle();
		$cell_renderer->set_property('activatable', true);
		$column = new \GtkTreeViewColumn('Select', $cell_renderer, 'active', 0);
		$cell_renderer->connect('toggled', array($this, 'on_toggle'), $model);
		
		$this->widgets['trvFiles']->add_column($cell_renderer, "Coluna 1", "active");
		$this->widgets['trvFiles']->add_column(new \GtkCellRendererText(), "Coluna 2", "text");
		$col = $this->widgets['trvFiles']->add_column(new \GtkCellRendererText(), "Coluna 3", "text");
		$col->set_visible(FALSE);
		$box->pack_start(\Fabula::GtkViewPort($this->widgets['trvFiles']), TRUE);
		
		
		$this->widgets['trvFiles']->set_highlight("#FFFFFF", "#EFEFEF");
		$this->widgets['trvFiles']->set_headers_visible(FALSE);
		
		// Inicia a aplicação
		$this->widgets['frmObfuscator']->add($box);
		$this->_signals();
		$this->frmObfuscator_onload();
	}
	
	/**
	 * Conecta os sinais dos widgets
	 *
	 * @name _signals
	 */
	private function _signals() {
		$this->widgets['tlbMain']->connect("clicked", array($this, "tlbMain_onclick"));
		$this->widgets['frmObfuscator']->connect("destroy", array($this, "frmObfuscator_unload"));
	}
	
	/**
	 * Toggle do check do treevew
	 */
	public function on_toggle($renderer, $row, $model) {
		$iter = $model->get_iter($row);
		$model->set($iter, 0, !$model->get_value($iter, 0));
	}
}
